import vuex from 'vuex'
import Vue from "vue";

Vue.use(vuex);

const state = {
    token: '',
    userInfo: {},
    screenWidth: document.documentElement.clientWidth, //屏幕宽度
    screenHeight: document.documentElement.clientHeight, //屏幕高度
    scrollTop: document.documentElement.scrollTop, //滚动高度
};

export default new vuex.Store({
    state,
    mutations: {
        ...Object.keys(state).reduce((obj, key) => {
            return {
                ...obj,
                [key]: (state, payload) => state[key] = payload
            }
        }, {})
    },
    getters: {
        ...Object.keys(state).reduce((obj, key) => {
            return {
                ...obj,
                [key]: (state) => state[key]
            }
        }, {})
    }
})